package tuanvn.iti.vn;

import java.util.List;
import java.util.Random;

import mrtran.iti.vn.Main;
import mrtran.iti.vn.Main.GameView;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.location.Address;

public class SpriteMonster1 {

	private GameView gameView1;
	private Bitmap monster1;
	private int widthMonster;
	private int heightMonster;
	private static final int BMP_COLUMNS_MONSTER = 7;
	private static final int BMP_ROWS_MONSTER = 2;
	public static int distance1;
	public static int monsterWidth1,widthLuffyMonster1;
	public static int xMonsterCenter1,yMonsterCenter1;
	private List<SpriteMonster1> spriteMonster1;
	
	int currentFrame1 = 0;
	int xSpeedMonster1 = 10, ySpeedMonster1 = 0;
	int xMonster1=Main.SCREENWIDTH,yMonster1 = Main.SCREENHEIGHT/2;
	int[] DIRECTION_TO_ANIMATION_MONSTER1 = {0,1};

	
	public SpriteMonster1(GameView gameView1, Bitmap monster1,List<SpriteMonster1> spriteMonster1) {
		this.gameView1 = gameView1;
		this.monster1 = monster1;
		this.distance1 = distance1;
		this.widthMonster = monster1.getWidth() / BMP_COLUMNS_MONSTER;
		this.heightMonster = monster1.getHeight() / BMP_ROWS_MONSTER;
		this.spriteMonster1 = spriteMonster1;
	}

	private void update() {	
			xMonster1-=xSpeedMonster1;
		    currentFrame1 = ++currentFrame1 % BMP_COLUMNS_MONSTER;	
	
			xMonsterCenter1 = xMonster1+widthMonster/2;
			yMonsterCenter1 = yMonster1+heightMonster/2;
			monsterWidth1 = widthMonster/2;	   
			if(xMonster1<Main.SCREENWIDTH/90-widthMonster-widthMonster){spriteMonster1.remove(this);}	
		}

	public void onDraw(Canvas canvas) {
		update();
		int srcX1 = currentFrame1 * widthMonster;
		int srcY1 = getAnimationRowMonster1() * heightMonster;
		Rect src1 = new Rect(srcX1, srcY1, srcX1 + widthMonster, srcY1
				+ heightMonster);
		Rect dst1 = new Rect(xMonster1, yMonster1, xMonster1 + widthMonster,
				yMonster1 + heightMonster);
		canvas.drawBitmap(monster1, src1, dst1, null);
		
	}

	private int getAnimationRowMonster1() {
		double dirDouble = (Math.atan2(xSpeedMonster1, ySpeedMonster1)
				/ (Math.PI / 2) + 2);
		int direction = (int) Math.round(dirDouble) % BMP_ROWS_MONSTER;
		return DIRECTION_TO_ANIMATION_MONSTER1[direction];
	}

}
